package app.stock.client;

import java.awt.Frame;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.JComboBox;

import app.stock.common.Constants;
import app.stock.common.Stock;
import app.stock.common.Transaction;

public class TransactionPanelAdd extends TransactionPanel {

    public TransactionPanelAdd(Frame owner) {
        super(owner);
        initialize();
    }

    private void initialize() {
        stList = sm.getStockList(null);
        codeList = new ArrayList();
        nameList = new ArrayList();
        for (Object obj : stList) {
            Stock st = (Stock) obj;
            codeList.add(st.code);
            nameList.add(st.name);
        }
        jComboBoxCode = new JComboBox(codeList.toArray());
        jButtonOK.setText(Constants.label_operationSave);
        jButtonOK.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent evt) {
                jButtonOKMouseClicked(evt);
            }
        });
    }

    private void jButtonOKMouseClicked(MouseEvent evt) {
        System.out.println("jButtonOK.mouseClicked, event=" + evt);
        tx = new Transaction();
        contructTransaction();
        sm.addTransaction(tx);
        this.setVisible(false);
    }

} // @jve:decl-index=0:visual-constraint="28,-3"
